package de.fhhannover.inform.hnefatafl.gui;

import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JPanel;

public class StartPanel extends JPanel{
	
	
	private static final long serialVersionUID = 1L;
	private int width = 800;
	private int hight = 600;
	private JButton start;
	private JButton beschreibung;
	private JButton ende;
	
	private Image background;

	public StartPanel(){
		this.setSize(width, hight);
		this.setLayout(new GridBagLayout());
		GridBagConstraints c = new GridBagConstraints();
		c.fill = GridBagConstraints.VERTICAL;
		c.insets = new Insets(5, 5, 5, 5);
		c.anchor = GridBagConstraints.CENTER;
		
		try {
			   background        = ImageIO.read(ImageIO.class.getResource("/res/hnefatafl_hintergrund1_2.png"));
			}
			catch(IOException ex) {
			   System.out.println("Ausnahmefehler beim Laden einer Grafik!\nEine Grafik konnte nicht gelesen werden!");
			   ex.printStackTrace();
			}
			catch(IllegalArgumentException ex) {
			   System.out.println("Ausnahmefehler beim Laden einer Grafik!\nEine Grafik wurde nicht gefunden!");
			   ex.printStackTrace();
			}
		
		start = new JButton("Start");
		c.gridy++;
		this.add(start, c);
		start.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				GUIController.getInstance().switchStartToGame();
				
			}});
		
		beschreibung = new JButton("Beschreibung");
		c.gridy++;
		this.add(beschreibung, c);
		beschreibung.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				GUIController.getInstance().switchStartToManual();
				
			}});
		
		ende = new JButton("Beenden");
		c.gridy++;
		this.add(ende, c);
		ende.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				GUIController.getInstance().exitGame();
				
			}});
		
	}
	
	@Override
	public void paintComponent(Graphics g){
		super.paintComponent(g);
		g.drawImage(background, 0, 0, this);
	}

}
